<?php 
require_once 'libs/required.php';
require_once 'DbTables/user.class.php';

if($_POST)
{
	$email    = $_POST['email'];
	$password = sha1($_POST['password']);
	$o_User = $o_UserModel->o_fLogin($email, $password);

	if($o_User)
	{
		$_SESSION['user'] = $o_User;
		$sz_Ticket = sz_fBase64Encode($o_User->user_username . $o_User->user_password . session_id());
		$_SESSION['user']->sz_Ticket = $sz_Ticket;
		if($o_User->user_roles== NORMAL)
			header('Location: home.php?ticket='.$sz_Ticket);
		if($o_User->user_roles== ADMIN)
			header('Location: admin/question.php');
	}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Sign In to play game</title>
    <script src="scripts/jquery-1.9.1.min.js"></script>
    <script src="scripts/bootstrap.min.js"></script>
    <script src="scripts/jquery.validate.min.js"></script>
    <link href="styles/bootstrap.css" rel="stylesheet" />
    <link href="styles/site.css" rel="stylesheet" />
    <link href="styles/img/favicon.ico" rel="shortcut icon" />
</head>
<body>
   <div class="container">
      <form class="form-signin" action="login.php" method="POST" id='input_form'>
		<h2 class="form-signin-heading">Please sign in</h2>
        <input type="text" placeholder="Email address or Username" class="input-block-level" name="email" id="email"  class="required email"/>
        <input type="password" placeholder="Password" class="input-block-level" name="password" id="password"  class="required"/>
        <button type="submit" class="btn btn-large btn-primary btn-success">Sign in</button>
        <div><a href="register.php">Sign up</a></div>
      </form>
    </div>
</body>
</html>
<?php
ob_flush();
?>
<script>
	$(document).ready(function(){
	    var validator = $("#input_form").validate({ 
	        rules: {  
	            email: { 
	                required: true
	            },
	            password: { 
	                required: true 
	            }
	        }, 
	        messages: { 
	            email: { 
	                required: "Email or Username is required", 
	            }, 
	            password: { 
	                required: "Password is required."
	            }
	        }
	    }); 
	});
</script>